package spring.data.redis.demo2;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;


@Repository
public class Dao {

	@CachePut(value="student", key="#stu.id")
	public Student save(Student stu){
		
		System.out.println("数据库保存：" + stu.getId());
		return stu;
	}
	
	@CachePut(value="student", key="#stu.id")
	public Student update(Student stu){
		
		System.out.println("数据库更新：" + stu.getId());
		return stu;
	}
	
	@Cacheable(value="student", key="#id")
	public Student get(String id){
		
		Student stu = new Student(id, "涂有" + id, 25);
		System.out.println("数据库获取：" + id);
		return stu;
	}
	
	@CacheEvict(value="student", key="#id")
	public void remove(String id){
		
		System.out.println("数据库删除：" + id);
	}
}
